<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
	body{
		width:300px;
		background-color:white;
		padding-left:20px;
	}
	
	input{
		border:2px solid gray;
		border-radius: 10px;
		background-color: white;
	}
</style>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-3.5.1.min.js">

</script>
<script type="text/javascript">
$(function(){
	$("#form").submit(check);
});

function check(){
	var flag =$("#input").val();
	var flags= true;
	$.ajax({
		url:"/movies/ManegerServlet?action=typeList",
		async:false,
		type:"get",
		data:"name="+name,
		success:function(s){
			var list =JSON.parse(s);
			
			for(var i =0;i<list.length;i++){
				if(list[i].movieType==flag){
					flags=false;
					alert("已存在");
					break;
				}
			}			
		}
	});
	
	
	if(flag==""){
		flags= false;
	}
	return flags;
}
</script>
</head>
<body>

<% 
  	String error =request.getParameter("error");

	if("1".equals(error)){%>
		<div style="color:green;">添加成功</div>
	<%}
%>
<form id="form" action="<%=request.getContextPath()%>/ManegerServlet?action=addType" method="post">
	   
	   		类型:<input type="text"  name="type" id="input"><br><br>	
	   	
	   		<input type="submit"  value="添加">
	  
	       </form>
</body>
</html>